package trim.gui.testing.components;

/**
 * Создан 08.11.2009 18:36:21
 */
import java.awt.Font;

public class JFontChooserDialog extends javax.swing.JDialog
{
    public final static int CANCEL_OPTION = 0;
    public final static int OK_OPTION = 1;

    private int exitCode = CANCEL_OPTION;

    /** Creates new form JFontChooserDialog */
    public JFontChooserDialog(java.awt.Frame parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
    }
    public JFontChooserDialog(java.awt.Dialog parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
    }

    private void initComponents()
    {
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        fontChooser1 = new FontChooserPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Select a font.");

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);

        jButton2.setText("CANCEL");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
        getContentPane().add(fontChooser1, java.awt.BorderLayout.CENTER);

        pack();
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
    {
        exitCode = CANCEL_OPTION;
        dispose();
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
    {
        exitCode = OK_OPTION;
        dispose();
    }

    public int getExitCode()
    {
        return exitCode;
    }

    public Font getSelectedFont()
    {
        return fontChooser1.getSelectedFont();
    }

    public static Font showFontDialog(java.awt.Frame parent, boolean modal)
    {
        JFontChooserDialog dialog = new JFontChooserDialog(parent, modal);
        dialog.setLocationRelativeTo(parent);
        dialog.pack();
        dialog.setVisible(true);

        if (dialog.getExitCode() == JFontChooserDialog.CANCEL_OPTION)
        {
            return null;
        }
        return dialog.getSelectedFont();
    }
    public static Font showFontDialog(java.awt.Dialog parent, boolean modal)
    {
        JFontChooserDialog dialog = new JFontChooserDialog(parent, modal);
        dialog.setLocationRelativeTo(parent);
        dialog.pack();
        dialog.setVisible(true);

        if (dialog.getExitCode() == JFontChooserDialog.CANCEL_OPTION)
        {
            return null;
        }
        return dialog.getSelectedFont();
    }

    private FontChooserPanel fontChooser1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
}